home *** CD-ROM | disk | FTP | other *** search
/ JCSM Shareware Collection 1996 September / JCSM Shareware Collection (JCS Distribution) (September 1996).ISO / bother__ / cenvid.zip / CENVIDOS.ZIP / VLABEL.BAT < prev    next >
DOS Batch File  |  1994-10-06  |  4KB  |  128 lines

  1. @echo off
  2. REM ***************************************
  3. REM *** VLabel.bat - Read or set volume ***
  4. REM *** ver.2        label for a drive  ***
  5. REM ***************************************
  6.  
  7. CEnviD %0.bat %1 %2 %3 %4 %5 %6 %7 %8 %9
  8. GOTO CENVI_EXIT
  9.  
  10. main(argc,argv)
  11. {
  12.    if ( argc < 2  ||  3 < argc
  13.      || strcmp( (drive=argv[1]) + 1, ":" )
  14.      || !isalpha(drive[0]) ) {
  15.       Instructions();
  16.       return(EXIT_FAILURE);
  17.    }
  18.  
  19.    // get current volume label
  20.    #define _A_VOLID  0x08  // Volume label
  21.    sprintf(SearchSpec,"%c:\\*.*",drive[0]);
  22.    if ( CurrentName = SearchFirstMatch(_A_VOLID,SearchSpec,dummy) ) {
  23.       // get rid of annoying period
  24.       strcpy(CurrentName+8,CurrentName+9);
  25.       printf("Current %c: Label is \"%s\"\n",toupper(drive[0]),CurrentName);
  26.    } else
  27.       printf("No current Label for %c:\n",toupper(drive[0]));
  28.  
  29.    if ( 3 == argc ) {
  30.       // set the new label
  31.       if ( !SetVolumeLabel(drive[0],argv[2]) ) {
  32.          printf("\aError setting new volume label for %c:\n",toupper(drive[0]));
  33.          return(EXIT_FAILURE);
  34.       }
  35.    } else {
  36.       // set VLABEL to new name
  37.       undefine(VLABEL);
  38.       if ( CurrentName )
  39.          VLABEL = CurrentName;
  40.    }
  41.  
  42.    return(EXIT_SUCCESS);
  43. }
  44.  
  45. Instructions()
  46. {
  47.    printf("\a\n")
  48.    printf("VLabel - Get or Set a disk volume label\n")
  49.    printf("\n")
  50.    printf("SYNTAX: VLABEL <d>: [NewLabel]\n")
  51.    printf("\n")
  52.    printf("Where: <d> Drive designation (e.g. A:, B:, C:, etc...)\n")
  53.    printf("       NewLabel - New volume name (truncated after 11 characters)\n")
  54.    printf("\n")
  55.    printf("Examples: VLABEL A:\n")
  56.    printf("          VLABEL A: MYTRANSFER\n")
  57.    printf("\n")
  58.    printf("NOTE: If retrieving volume label then set the VLABEL environment variable\n")
  59.    printf("      to the name of the volume.\n")
  60.    printf("\n")
  61.    printf("ERRORLEVEL: Sets ERRORLEVEL %d for error, %d if success\n",EXIT_FAILURE,EXIT_SUCCESS)
  62.    printf("\n")
  63. }
  64.  
  65. SearchFirstMatch(FileAttribute,FileName,FoundAttribute)
  66. {  // return name found, else NULL
  67.    reg.ah = 0x4E;
  68.    reg.cx = FileAttribute;
  69.    reg.ds = segment(FileName);
  70.    reg.dx = offset(FileName);
  71.    if ( !interrupt(0x21,reg) )
  72.       return NULL;
  73.    lDTA = GetDTAaddress();
  74.    FoundAttribute = peek(lDTA+21,UWORD8);
  75.    strcpy(lFoundName,peek(lDTA+30,13));
  76.  
  77.    return lFoundName;
  78. }
  79.  
  80. GetDTAaddress()   // return pointer to Data Transmission Area
  81. {
  82.    reg.ah = 0x2F;
  83.    interrupt(0x21,reg);
  84.    return Address(reg.es,reg.bx);
  85. }
  86.  
  87.  
  88. SetVolumeLabel(pDriveLetter,pName)  // return True for success, else False
  89. {
  90.    // drive letter convert to drive number 1 - 26
  91.    lDriveNumber = toupper(pDriveLetter) - 'A' + 1;
  92.  
  93.    // Create FCB blob for old-style FCB functions
  94.    // Set up initial fields for FCB
  95.    BLObSize(lFCB,8 + 37);
  96.    memset(lFCB,0,BLObSize(lFCB));
  97.    BLObPut(lFCB,0,255,UWORD8);
  98.    BLObPut(lFCB,6,8,UWORD8);
  99.    BLObPut(lFCB,7,lDriveNumber,UWORD8);
  100.  
  101.    // Delete current volume ID
  102.    BLObPut(lFCB,8,'*       *  ',11);
  103.    reg.ah = 0x13;
  104.    reg.ds = segment(lFCB);
  105.    reg.dx = offset(lFCB);
  106.    interrupt(0x21,reg);
  107.    undefine(reg);
  108.  
  109.    // Create new volume file; local name must be 11 characters, blank-padded
  110.    sprintf(lName,"%s                  ",pName);
  111.    memcpy(lFCB+8,lName,11);
  112.    reg.ah = 0x16;
  113.    reg.ds = segment(lFCB);
  114.    reg.dx = offset(lFCB);
  115.    interrupt(0x21,reg);
  116.    if ( reg.al ) return False;
  117.    undefine(reg);
  118.  
  119.    // Close the file
  120.    reg.ah = 0x10;
  121.    reg.ds = segment(lFCB);
  122.    reg.dx = offset(lFCB);
  123.    interrupt(0x21,reg);
  124.    return( reg.al ? False : True );
  125. }
  126.  
  127. :CENVI_EXIT
  128.